using System;
using System.IO;

namespace ByteFarm.ImageMetaData.Format.Tiff
{
    public class TiffReader : Reader
    {
        public TiffReader(ByteOrder byteOrder, BinaryReader reader)
            : base(byteOrder, reader)
        {
        }

        public Rational ReadRational()
        {
            return new Rational(ReadInt32(), ReadInt32());
        }

        public URational ReadURational()
        {
            return new URational(ReadUInt32(), ReadUInt32());
        }


        public object Read(FieldType type)
        {
            switch (type)
            {
                case FieldType.Byte:
                    return ReadByte();
                case FieldType.Ascii:
                    return ReadChar();
                case FieldType.Double:
                    return ReadDouble();
                case FieldType.Single:
                    return ReadSingle();
                case FieldType.Int16:
                    return ReadInt16();
                case FieldType.Int32:
                    return ReadInt32();
                case FieldType.Rational:
                    return ReadRational();
                case FieldType.SByte:
                    return ReadSByte();
                case FieldType.UInt16:
                    return ReadUInt16();
                case FieldType.UInt32:
                    return ReadUInt32();
                case FieldType.URational:
                    return ReadURational();
                case FieldType.Undefined:
                    return ReadByte();
                default:
                    throw new Exception("Unknown FieldType");
            }
        }
    }
}